package com.sghd.football.utils;

import com.sghd.common.socket.utils.Crypt;
import com.sghd.common.utils.json.JsonUtils;
import com.sghd.football.utils.encrypt.DecryptUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author wch
 * @date 2018-07-13 17:31
 * @desc 加解密止下文对象
 **/
@Component
public class CryptContext implements Crypt {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public String encode(String content) throws Exception {
        logger.warn("未实现加密[{}]", this.getClass().getName());
        return content;
    }

    /**
     * 解密
     * @param content
     * @return
     * @throws Exception
     */
    @Override
    public String decode(String content) throws Exception {
        Map<String, Object> params = JsonUtils.string2Map(content.replaceAll(" ", "+"));
        Map<String, Object> result = DecryptUtil.getValidData(params);
        return JsonUtils.object2String(result);
    }
}
